﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Module_Debug.Others
{
    public partial class Logic_SeekXY : Form
    {
        frmMain frmHelp = null;
        private byte[] ImageData;
        public Logic_SeekXY(frmMain SeekXY)
        {
            frmHelp = SeekXY;
            InitializeComponent();
        }
        private void Logic_SeekXY_Load(object sender, EventArgs e)
        {
            ImageData = new byte[(int)(frmHelp.HACT.Value) * (int)(frmHelp.VACT.Value) * 3];
            //数组转换为Intptr
            IntPtr pData = Marshal.AllocHGlobal((int)(frmHelp.HACT.Value) * (int)(frmHelp.VACT.Value * 3)); //托管空间
            for (int i = 0; i < (int)(frmHelp.HACT.Value) * (int)(frmHelp.VACT.Value) * 3; i++)
            {
                ImageData[i] = (byte)(frmHelp.HFZ_M_B.Value);
                ImageData[i + 1] = (byte)(frmHelp.HFZ_M_G.Value);
                ImageData[i + 2] = (byte)(frmHelp.HFZ_M_R.Value);
                i = i + 2;
            }
            Marshal.Copy(ImageData, 0, pData, (int)(frmHelp.HACT.Value) * (int)(frmHelp.VACT.Value) * 3);
            Bitmap bmp = new Bitmap((int)(frmHelp.HACT.Value), (int)(frmHelp.VACT.Value), (int)(frmHelp.HACT.Value) * 3, PixelFormat.Format24bppRgb, pData);
            pictureBox1.Image = bmp;
        }

        private void PictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            frmHelp.HFZ_CX.Value = Math.Round(frmHelp.HACT.Value * Convert.ToInt16(e.X) / pictureBox1.Size.Width);
            frmHelp.HFZ_CY.Value = Math.Round(frmHelp.VACT.Value * Convert.ToInt16(e.Y) / pictureBox1.Size.Height);
            labelX.Text = frmHelp.HFZ_CX.Value.ToString();
            labelY.Text = frmHelp.HFZ_CY.Value.ToString();
            frmHelp.OLED_Show_Click(frmHelp.btnlogic_go, e);
        }
        private void Logic_SeekXY_KeyDown(object sender, KeyEventArgs e)
        {
            this.Close();
        }

        private void Logic_SeekXY_ResizeEnd(object sender, EventArgs e)
        {
            pictureBox1.Size = new System.Drawing.Size(Logic_SeekXY.ActiveForm.Width - 22, Logic_SeekXY.ActiveForm.Height - 65);
        }
    }
}
